package com.sfx.concurrent.demo.concurrent.AtomicTest.demo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-01-18
 * Time: 16:24
 */
public class AccountUnSafe implements Account{

    private Integer balance;

    public AccountUnSafe(Integer balance) {
        this.balance = balance;
    }

    @Override
    public synchronized Integer getBalance() {
       synchronized (this) {
           return this.balance;
       }
    }

    @Override
    public synchronized void withDraw(Integer money) {
         this.balance -= money;
    }

    public static void main(String[] args) {
        Account account = new AccountUnSafe(10000);
        Account.demo(account);
    }
}
